<template>
  <div class="users">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>
        权限管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表格 -->
    <el-table :data="rightList">
      <el-table-column label="权限名称" prop="authName"></el-table-column>
      <el-table-column label="路径" prop="path"></el-table-column>
      <el-table-column label="层级">
        <template v-slot:default="{ row }">
          <span v-if="row.level === '0'">一级</span>
          <span v-if="row.level === '1'">二级</span>
          <span v-if="row.level === '2'">三级</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 6, 8, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      type: 'list',
      total: 1,
      currentPage: 1,
      pageSize: 6,
      rightList: []
    }
  },
  methods: {
    async getRightList () {
      const { meta, data } = await this.$axios.get(`/rights/${this.type}`)
      if (meta.status === 200) {
        console.log(data)
        this.rightList = data.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
        this.total = data.length
      } else {
        this.$message.error(meta.msg)
      }
    },
    handleSizeChange (val) {
      this.pageSize = val
      this.currentPage = 1
      this.getRightList()
    },
    handleCurrentChange (val) {
      this.currentPage = val
      this.getRightList()
    }
  },
  created () {
    this.getRightList()
  }
}
</script>

<style lang='scss' scoped>
  .el-table{
    margin-top: 20px;
  }
</style>
